package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * 呼叫状态枚举信息 youli.chen
 * @time 2018-12-06 11:20
 * @author  youli.chen
 */
@Getter
public enum CallStatusEnum {

    PHONE_ERROR(1,"enum.callStatus.name.phone_error","PHONE_ERROR"),
    PHONE_NULL_OR_STOP(2,"enum.callStatus.name.phone_null_or_stop","PHONE_NULL_OR_STOP"),
    POWER_OFF(3,"enum.callStatus.name.power_off","POWER_OFF"),
    NET_BUSY(4,"enum.callStatus.name.net_busy","NET_BUSY"),
    ON_THE_PHONE(5,"enum.callStatus.name.on_the_phone","ON_THE_PHONE"),
    HUNG_UP(6,"enum.callStatus.name.hung_up","HUNG_UP"),
    INCOMING_CALL_BARRING (7,"enum.callStatus.name.incoming_call_barring","INCOMING_CALL_BARRING"),
    NOT_ANSWERING(8," enum.callStatus.name.not_answering","NOT_ANSWERING"),
    NORMAL (9," enum.callStatus.name.normal","NORMAL"),
    UNKNOWN(XbbRefTypeEnum.UNKNOWN.getCode(), "enum.callStatus.name.unknown", "UNKNOWN");

    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    /**
     * 构造一个枚举对象
     * @param code  枚举值
     * @param name  枚举类型名
     * @param alias 枚举类型英文别名
     */
    CallStatusEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举 alias 获得枚举
     * @param alias 枚举类型英文别名
     * @return CallLogResultEnum
     */
    public static CallStatusEnum getByAlias(String alias) {
        for (CallStatusEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举 code 获得枚举
     * @param code 枚举类型英文别名
     * @return CallLogResultEnum
     */
    public static CallStatusEnum getByCode(Integer code) {
        for (CallStatusEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     * @return List<CallLogResultEnum>
     */
    public List<CallStatusEnum> getAllEnum() {
        List<CallStatusEnum> list = new ArrayList<>();
        for (CallStatusEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (CallStatusEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
